//
//  SHEmoticonPageView.swift
//  SHWeibo01
//
//  Created by 卫平玉 on 16/7/29.
//  Copyright © 2016年 卫平玉. All rights reserved.
//

import UIKit
private let SHEmoticonPageViewCellId = "SHEmoticonPageViewCellId"

class SHEmoticonPageView: UICollectionView {

    override init(frame: CGRect, collectionViewLayout layout: UICollectionViewLayout) {
        
        super.init(frame: frame, collectionViewLayout: UICollectionViewFlowLayout())
        
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    func setupUI(){

        backgroundColor = RandomColor()
        
        registerClass(SHEmoticonPageViewCell.self, forCellWithReuseIdentifier: SHEmoticonPageViewCellId)
        
        let layout = self.collectionViewLayout as! UICollectionViewFlowLayout
        
        layout.itemSize = CGSize(width: SCREENW, height: 216 - 37)
        
        layout.minimumInteritemSpacing = 0
        
        layout.minimumLineSpacing = 0
        
        layout.scrollDirection = .Horizontal
        
         dataSource = self
    }

}

extension SHEmoticonPageView: UICollectionViewDataSource{
    
    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
//         print(SHEmoticonTools.sharedTools.allEmoticons.count)
        return SHEmoticonTools.sharedTools.allEmoticons.count
    }
    
    func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
//         print(SHEmoticonTools.sharedTools.allEmoticons[section].count)
        return SHEmoticonTools.sharedTools.allEmoticons[section].count
    }
    
    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCellWithReuseIdentifier(SHEmoticonPageViewCellId, forIndexPath: indexPath) as! SHEmoticonPageViewCell
//        cell.indexPath = indexPath
        
        //获取数据
        cell.emoticons = SHEmoticonTools.sharedTools.allEmoticons[indexPath.section][indexPath.item]
        cell.backgroundColor = self.backgroundColor
        
        return cell
    }
    
    
}
